#! /usr/bin/env python

from _struct import pack
from os import SEEK_SET


cache_bits = list("\0") * (2 ** 32 >> 4)
def bit_mask(pos):
    global cache_bits

    pos -= 1
    shift = 7 - (pos % 8)
    pos >>= 3

    # 我们暂时忽略不能表示的范围
    if pos >= len(cache_bits):
        return False

    byte = ord(cache_bits[pos])
    rv = True
    mask = 1 << shift
    if not (byte & mask):
        rv = False
        byte |= mask
        cache_bits[pos] = chr(byte)

    return rv


def run():
    i = 1
    M = 2 ** 31

    while i < M:
        x = hash(pack('L', i))
        if x < 0:
            x += 2 ** 32

        i += 1
        rv = bit_mask(x)
        if rv:
            print '%s %s' % (i, x)


def test():
    global cache_bits

    print len(cache_bits), cache_bits.count('\0')


if __name__ == '__main__':
    run()

